<?php
	header ('Access-Control-Allow-Origin: *');
	header ('Access-Control-Allow-Methods: POST');

	include ('function/conn.php');
	include ('function/function.php');

	function appendBook($uid, $bid, $title, $author) {
		if (!$uid || empty($uid)) {
			$returnObject = (object) array(
				"error_code" => 2000,
				"error_msg" => "参数错误：uid不能为空",
			);

			return $returnObject;
		}

		if (!$bid || empty($bid)) {
			$returnObject = (object) array(
				"error_code" => 2001,
				"error_msg" => "参数错误：bid不能为空",
			);

			return $returnObject;
		}

		if (!$title || empty($title)) {
			$returnObject = (object) array(
				"error_code" => 2002,
				"error_msg" => "参数错误：title不能为空",
			);

			return $returnObject;
		}

		if (!$author || empty($author)) {
			$returnObject = (object) array(
				"error_code" => 2003,
				"error_msg" => "参数错误：author不能为空",
			);

			return $returnObject;
		}
		
		$result = mysql_query("select * from `book-lite_list` where uid='$uid' and bid='$bid' limit 1");

		if ($result) {
	    	if (mysql_num_rows($result) > 0) {
		    	mysql_query("update `book-lite_list` set bid='$bid', title='$title', author='$author', uid='$uid', last_read=CURRENT_TIMESTAMP where bid='$bid' and uid='$uid' limit 1");
	    	} else {
		    	mysql_query("insert into `book-lite_list` (bid, title, author, uid, last_read) values ('$bid', '$title', '$author', '$uid', CURRENT_TIMESTAMP)");
	    	}
		}

		$returnObject = (object) array (
			"result" => $result != null
		);

		mysql_free_result($result);

		return $returnObject;
	}
?>